package com.shuyuansystem.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.atomic.AtomicInteger;

public class OrderInfoUtils{

    private static final String BUSINESS_IDENTIFIER = "SHOP";
    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
    private static final AtomicInteger sequence = new AtomicInteger(1);

    /**
     * 生成订单号
     * @return 生成的订单号
     */
    public static String generateOrderNumber(String userId) {
        // 获取当前日期
        String date = DATE_FORMAT.format(new Date());

        // 获取自增序列
        int seq = sequence.getAndIncrement();

        // 组合订单号
        return userId+BUSINESS_IDENTIFIER + date + String.format("%04d", seq);
    }


}